package com.dachuang.canjiren.service.impl;

import com.dachuang.canjiren.entity.Application;
import com.dachuang.canjiren.mapper.ApplicationMapper;
import com.dachuang.canjiren.mapper.BannerMapper;
import com.dachuang.canjiren.service.ApplicationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dachuang.common.exception.BizCodeEnume;
import com.dachuang.common.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author testjava
 * @since 2020-07-27
 */
@Service
public class ApplicationServiceImpl implements ApplicationService {
    @Autowired
    private ApplicationMapper applicationMapper;
    @Override
    public R insertApplication(String name, String cardNumber, String phone, String activity, String introduction, String plan, Integer volunteerId) {
            if (StringUtils.isEmpty(name)) {
                return R.error(BizCodeEnume.ERROR50001);
            }
            if (StringUtils.isEmpty(cardNumber)) {
                return R.error(BizCodeEnume.ERROR50002);
            }
            if (StringUtils.isEmpty(phone)) {
                return R.error(BizCodeEnume.ERROR50003);
            }
            if (StringUtils.isEmpty(activity)) {
                return R.error(BizCodeEnume.ERROR50004);
            }
            if (StringUtils.isEmpty(introduction)) {
                return R.error(BizCodeEnume.ERROR50005);
            }
            if (StringUtils.isEmpty(plan)) {
                return R.error(BizCodeEnume.ERROR50006);
            }
            Application application = new Application();
            application.setName(name);
            application.setCardNumber(cardNumber);
            application.setPhone(phone);
            application.setActivity(activity);
            application.setIntroduction(introduction);
            application.setPlan(plan);


            int i = applicationMapper.insertApplication(application);
            if (i > 0) {
                return R.ok();
            }
            return R.error();
    }
}
